home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / program / misc / fpl-v13.lha / fpl / src / frontend.c < prev    next >
C/C++ Source or Header  |  1995-08-11  |  6KB  |  179 lines

  1. /******************************************************************************
  2.  *                   FREXX PROGRAMMING LANGUAGE                  *
  3.  ******************************************************************************
  4.  
  5.  frontend.c
  6.  
  7.  All frontend functions.
  8.  
  9.  *****************************************************************************/
  10.  
  11. /************************************************************************
  12.  *                                                                      *
  13.  * fpl.library - A shared library interpreting script langauge.         *
  14.  * Copyright (C) 1992-1994 FrexxWare                                    *
  15.  * Author: Daniel Stenberg                                              *
  16.  *                                                                      *
  17.  * This program is free software; you may redistribute for non          *
  18.  * commercial purposes only. Commercial programs must have a written    *
  19.  * permission from the author to use FPL. FPL is *NOT* public domain!   *
  20.  * Any provided source code is only for reference and for assurance     *
  21.  * that users should be able to compile FPL on any operating system     *
  22.  * he/she wants to use it in!                                           *
  23.  *                                                                      *
  24.  * You may not change, resource, patch files or in any way reverse      *
  25.  * engineer anything in the FPL package.                                *
  26.  *                                                                      *
  27.  * This program is distributed in the hope that it will be useful,      *
  28.  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
  29.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                 *
  30.  *                                                                      *
  31.  * Daniel Stenberg                                                      *
  32.  * Ankdammsgatan 36, 4tr                                                *
  33.  * S-171 43 Solna                                                       *
  34.  * Sweden                                                               *
  35.  *                                                                      *
  36.  * FidoNet 2:201/328    email:dast@sth.frontec.se                       *
  37.  *                                                                      *
  38.  ************************************************************************/
  39.  
  40. #if defined(AMIGA)
  41. #include <exec/types.h>
  42. #include <proto/exec.h>
  43. #elif defined(UNIX)
  44. #include <sys/types.h>
  45. #endif
  46.  
  47. #include "script.h"
  48. #include "debug.h"
  49. #include <stdio.h>
  50.  
  51. /***************************************************************************
  52.  *
  53.  * fplGetErrorMsg()
  54.  *
  55.  * Returns a char pointer to an error message to the error given as argument.
  56.  *
  57.  ******/
  58.  
  59. uchar * PREFIX
  60. fplGetErrorMsg(AREG(0) struct Data *scr,
  61.                DREG(0) long error,
  62.                AREG(1) uchar *buffer)
  63. {
  64. #ifdef DEBUGMAIL
  65.   DebugMail(scr, MAIL_FUNCTION, 500, "fplGetErrorMsg");
  66. #endif
  67.   return GetErrorMsg(scr, error, buffer);
  68. }
  69.  
  70. uchar * REGARGS
  71. GetErrorMsg(struct Data *scr,
  72.             long error,
  73.             uchar *buffer)
  74. {
  75.   /* All FPL error messages. */
  76.   static const uchar *errors[]={
  77.     "", /* not used */
  78.     "Division by zero",
  79.     "Illegal anchor",
  80.     "Illegal array:",   /* */
  81.     "Illegal assign",
  82.     "Illegal break",
  83.     "Illegal condition operator",
  84.     "Illegal continue",
  85.     "Illegal declaration",
  86.     "Illegal parameter",
  87.     "Illegal pre operation",
  88.     "Illegal prototype",
  89.     "Illegal resize",
  90.     "Illegal statement",
  91.     "Illegal variable type",
  92.     "Internal",
  93.     "Function not found:", /* */
  94.     "Missing apostrophe",
  95.     "Missing argument",
  96.     "Missing brace",
  97.     "Missing bracket",
  98.     "Missing operand",
  99.     "Missing parentheses",
  100.     "Missing semicolon",
  101.     "Incomplete statement",
  102.     "File",
  103.     "Out of memory",
  104.     "Parameter out of range",
  105.     "Out of stack space",
  106.     "Program stopped",
  107.     "Read only violation:", /* */
  108.     "Syntax",
  109.     "Unbalanced comment",
  110.     "Unexpected end of program",
  111.     "Unmatched brace",
  112.     "Identifier not found:",  /* */
  113.     "Identifier already used:", /* */
  114.  
  115.     "Missing colon",   /* from version 7 */
  116.     "Missing 'while'", /* from version 7 */
  117.  
  118.     /* These were added to version 11: */
  119.  
  120.     "Illegal 'case'",
  121.     "Illegal 'default'",
  122.     "Unexpected integer statement",
  123.     "Unexpected string statement",
  124.     "Illegal string index:",
  125.     "Illegal reference",
  126.     "Too many parameters",
  127.     
  128.     "Unknown" /* MUST be the last member */
  129.     };
  130.  
  131.   uchar len;
  132.   if(!scr || !buffer)
  133.     return(NULL);
  134.   strcpy(buffer, errors[((error>FPL_EXIT_OK) && (error<FPLERR_UNKNOWN_ERROR))?
  135.             (error-2):(FPLERR_UNKNOWN_ERROR-2)]);
  136.   len=strlen(buffer);
  137.   if(buffer[len-1]==':') {
  138.     /* Add " <buffer> ", but avoid sprintf() */
  139.     strcat(buffer, " \"");
  140.     strcat(buffer, scr->buf);
  141.     strcat(buffer, "\"");
  142.   }
  143.   strcat(buffer, " error!");
  144.   return(buffer);
  145. }
  146.  
  147. #ifdef AMIGA
  148. long PREFIX fplOpenLib(AREG(0) struct Data *scr,
  149.                        AREG(1) uchar *name,   /* funclib name */
  150.                        DREG(0) long version, /* version number required */
  151.                        DREG(1) long flags)
  152. {
  153.   long retval;
  154.   ReturnCode ret;
  155. #ifdef DEBUGMAIL
  156.   DebugMail(scr, MAIL_FUNCTION, 500, "fplOpenLib");
  157. #endif
  158.   CALL(OpenLib(scr, name, version, &retval, (uchar)flags));
  159.   if(retval)
  160.     return -retval;
  161.   return FPL_OK;
  162. }
  163.  
  164. long PREFIX fplCloseLib(AREG(0) struct Data *scr,
  165.                         AREG(1) uchar *name, /* funclib name */
  166.                         DREG(0) long force) /* boolean force close! */
  167. {
  168.   long retval;
  169.   ReturnCode ret;
  170. #ifdef DEBUGMAIL
  171.   DebugMail(scr, MAIL_FUNCTION, 500, "fplCloseLib");
  172. #endif
  173.   CALL(CloseLib(scr, name, FPLLIB_FORCE, &retval));
  174.   if(retval)
  175.     return -retval;
  176.   return FPL_OK;
  177. }
  178. #endif
  179.